-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[자동차 경주] 이해승 미션 제출합니다. #1467
base: main
Are you sure you want to change the base?
[자동차 경주] 이해승 미션 제출합니다. #1467
Conversation
구현할 기능 목록 정리
Model - car View - output Controller - RacingCarController 위와 같이 구성
자동차 이름이 없는 경우, 오류를 출력하는 것이 더 일반적으로 생각되어 기능 수정
자동차의 초기 위치가 정상적으로 결정되는지, 자동차 이름이 정상적으로 들어왔는지, 자동차가 잘 움직이는지, 자동차가 확률적으로 움직여지는지 등에 대한 car test코드 작성
이름 설정 후 확인하는 테스트 누락되어 추가
자동차 생성자 및 기본 구현 수행 이름 부여 가능하도록 구현
확률적으로 움직이는 기능이 구현됨에 따라 단순 전진/정지 기능은 private로 대체. 이에 따른 test 코드 또한 제거
람다식으로 수적
view와 controller에 대한 부분은 함께 test 진행
model 구현시 구현한 예외 처리로 인해 해결된 예외 사항 기록
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2주 차 고생많으셨습니다 😄
예외처리를 꼼꼼히 처리하신 부분이 인상깊네요!
3주 차도 파이팅 해봐요~!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Application과 Controller의 역할이 중복되는 것 같은데 통합된다면 좋을 것 같습니다!
public RacingCarController(Output output, List<Car> cars) { | ||
this.output = output; | ||
this.cars = cars; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
매개변수로 받아 컨트롤러를 생성하기보다는
public RacingCarController(Output output, List<Car> cars) { | |
this.output = output; | |
this.cars = cars; | |
} | |
public RacingCarController(Output output, List<Car> cars) { | |
this.output = new Output; | |
this.cars = new Cars; | |
} |
이런식으로 생성하는 생성하는게 나을 것 같아요
public class Application { | ||
public static void main(String[] args) { | ||
// TODO: 프로그램 구현 | ||
System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); | ||
String carNameStrings = Console.readLine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View에서 Output과 Input으로도 나누어 볼 수 있겠네요!
public void play(int time) { | ||
output.printResultString(); | ||
for (int i = 0; i < time; i++) { | ||
for (Car car : cars) { | ||
car.randomMove(); | ||
} | ||
output.printCars(cars); | ||
} | ||
List<String> winners = findWinner(); | ||
output.printWinners(winners); | ||
} | ||
|
||
public List<String> findWinner() { | ||
List<String> winners = new ArrayList<>(); | ||
int maxLocation = 0; | ||
|
||
for (Car car : cars) { | ||
if (maxLocation < car.getLocation()) { | ||
winners.clear(); | ||
winners.add(car.getName()); | ||
} else if (maxLocation == car.getLocation()) { | ||
winners.add(car.getName()); | ||
} | ||
} | ||
|
||
return winners; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 부분(비지니스 로직)은 model 쪽에서 관리할 수 있게 하는게 좋을 것 같아요.
controller의 역할은 입/출력 또는 Model과 View의 매개체라고 생각하시면 될 것같습니다!
public Car(String name) { | ||
location = 0; | ||
name = name.trim(); | ||
if (name.isEmpty() || name.length() > 5) { | ||
throw new IllegalArgumentException(); | ||
} | ||
this.name = name; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
검증하는 부분을 함수로 처리한다면 가독성이 높아질 것 같습니다.
public Car(String name) { | |
location = 0; | |
name = name.trim(); | |
if (name.isEmpty() || name.length() > 5) { | |
throw new IllegalArgumentException(); | |
} | |
this.name = name; | |
} | |
public Car(String name) { | |
location = 0; | |
name = name.trim(); | |
validateName(name); | |
this.name = name; | |
} |
validateName이라는 메서드를 만들어서 이런식으로 처리하면 좋습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output에 대한 분리는 잘하신 것 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자동차 이름 예외처리를 꼼꼼하게 처리하셨네요!
java-racingcar-precourse
기능 목록
IllegalArgumentException
을 발생시킨 후 애플리케이션은 종료되어야 한다.구현할 기능
자동차
입력
출력